package tests;

import common.Utils;
import org.openqa.selenium.By;

import java.io.IOException;
import java.util.Random;

/**
 * 测试个人中心 -- 需要在登陆后
 */

public class PersonData extends Utils {


    private static final String url = "http://110.41.148.165:13145/index.html"; //主页

    public PersonData() {
        super(url);
    }

    /**
     * 查看我的帖子
     */
    public void data1() {
        //1.点击头像，弹出详情页
        driver.findElement(By.cssSelector("#index_nav_avatar")).click();
        //2.点击我的帖子
        //driver.findElement(By.cssSelector("")).click();
        driver.findElement(By.cssSelector("#index_user_profile")).click();
        //3.查看页面是否正确
        driver.findElement(By.cssSelector("#bit-forum-content > div.page-header.d-print-none > div > div > div.col > div > div:nth-child(3)"));

        //4.回到首页
        driver.findElement(By.cssSelector("#nav_board_index > a")).click();
    }

    /**
     * 查看个人中心
     * @throws IOException
     */
    public void data2() throws IOException {
        //1.点击头像，弹出详情页
        driver.findElement(By.cssSelector("#index_nav_avatar")).click();
        //2.点击个人猪心
        //driver.findElement(By.cssSelector("")).click();
        driver.findElement(By.cssSelector("#index_user_settings")).click();
        //3.查看页面是否正确
        String expert = driver.findElement(By.cssSelector("#bit-forum-content > div.page-body > div > div > div > div.col-3.d-none.d-md-block.border-end > div > div > a")).getText();
//        System.out.println("expert: " + expert);

        //4.做修改操作

        String str;
        int rand = new Random().nextInt(10)+1;
        if(rand % 2 == 0) {
            str = "520";
        }else {
            str = "1314";
        }
        //1.修改邮箱地址
        driver.findElement(By.cssSelector("#setting_input_email")).clear();
        driver.findElement(By.cssSelector("#setting_input_email")).sendKeys(str);
        driver.findElement(By.cssSelector("#setting_submit_email")).click();
        //2.修改电话号码
        driver.findElement(By.cssSelector("#setting_input_phoneNum")).clear();
        driver.findElement(By.cssSelector("#setting_input_phoneNum")).sendKeys(str);
        driver.findElement(By.cssSelector("#setting_submit_phoneNum")).click();
        //3.修改个人简介
//        getScreenShot(PersonData.class.getName(),"data2()");
//        System.out.println("======");
//        driver.findElement(By.cssSelector("#settings_textarea_remark")).clear();
//        driver.findElement(By.cssSelector("#settings_textarea_remark")).click();
//        driver.findElement(By.cssSelector("#settings_textarea_remark")).sendKeys(str);
//        driver.findElement(By.cssSelector("#settings_submit_remark")).click();
//        System.out.println("-----");
//        getScreenShot(PersonData.class.getName(),"data2()");

        //4.验证是否已经修改
        String expect1 = driver.findElement(By.cssSelector("#setting_input_email")).getText();
        String expect2 = driver.findElement(By.cssSelector("#setting_input_phoneNum")).getText();

        assert expect1.equals(str);
        assert expect2.equals(str);

        //5.回到首页
        driver.findElement(By.cssSelector("#nav_board_index > a")).click();
    }


}
